<?php


namespace App\Repositories\Policy\Eloquent;


use Illuminate\Support\Facades\Storage;

class QuRepository
{
    protected $key    = ['agb.trade.qunar.com'=>'d06d94ab820713909ee5bc118f00b5f3'];
    protected $token  = ['agb.trade.qunar.com'=>'2609101debc9cf0d40ad613e19b8fd63'];

    /**
     * 上传地址
     * @var string[]
     */
    protected $urls = [
        'SINGLE' => 'http://agb.trade.qunar.com/tts/interface/policy.jsp',
        'STOCK' => 'http://agb.trade.qunar.com/tts/interface/policy.jsp',
        'ROUND' => 'http://agb.trade.qunar.com/tts/interface/policy.jsp',
    ];

    /**
     * 上传地址
     * @var string[]
     */
    protected $qnFenXiaoUrls = [
        'SINGLE' => 'http://ajp.trade.qunar.com/tts/interface/policy.jsp',
        'STOCK' => 'http://ajp.trade.qunar.com/tts/interface/policy.jsp',
        'STOCK_AV' => 'http://ajp.trade.qunar.com/tts/interface/policy.jsp',
    ];

    /**
     * 用户类型
     * @var \string[][]
     */
    protected $userInfo = [];

    public function __construct()
    {
        $this->userInfo = [
            'PolicyList' => [
                'username'  =>config('env.quna_upload_user'),
                'password'  =>config('env.quna_upload_pwd'),
                'ext'       =>'',

                /*'DeleteProduct' => [
                    'dpt'               => $flight[0]['flight_line']['depart_city_code'],
                    'arr'               => $flight[0]['flight_line']['arrived_city_code'],
                    'flightcondition'   => $flight[0]['flight_line']['hs_code'].$flight[0]['flight_code']
                ],*/
            ]
        ];
    }

    /**
     * 删除政策文件
     * @param $url
     * @param $xml
     */
    protected function uploadPolicy($url,$xml){

        //生成xml
        $filename = 'upload/qu/'.date('YmdHi');
        $xml->saveXml(\Storage::path($filename).'.xml');
        $xml->zip(\Storage::path($filename).'.xml',\Storage::path($filename).'.zip');

        $fileData = \Storage::get($filename.'.zip');
        $response = \Requests::post($url,['Content-Type'=>'multipart/form-data'],$fileData,['timeout'=>100]);
        logger($response->body);

        //\Storage::delete([$filename.'.xml',$filename.'.zip']);

        return $response->body;
    }


}